<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="收益者UUID" class="w200 m-r10" v-model.trim="uuid" />
				<Input type="text" placeholder="收益者用户" class="w200 m-r10" v-model.trim="userName" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="getQuery" :current.sync="page"></Page>
		<Modal v-model="modal1" title="每天收益详情" width='55%'>
			<Input type="text" placeholder="提供者UUID" class="w200 m-r10" v-model.trim="uuid2" />
			<Input type="text" placeholder="提供者用户" class="w200 m-r10" v-model.trim="userName2" />
			<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime2">
			</DatePicker>
			<Button type="primary" v-on:click="getQueryById">查询</Button>
			<Table class="m-t10" stripe :columns="columns1" :data='list1' :loading="loading2" ref="table"></Table>
			<Page :total="info2" show-elevator :page-size="pageSize2" show-total @on-change="getQueryById" :current.sync="page2"></Page>
		</Modal>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				loading2: true,
				jsonData: [],
				list: [], // 分享收益列表数据
				list1: [], // 分享收益列表数据
				num: '', // 累计分享收益
				info: null, // 总条数
				info2: null, // 总条数
				page: 1, // 页数
				page2: 1, // 页数
				pageSize: 20, // 每页多少条
				pageSize2: 10, // 每页多少条
				downList: [],
				dataValue: ['', ''], // 时间段值
				dataValue2: ['', ''], // 时间段值
				uuid: '', // 用户 ID
				userName: '', // 手机号码
				uuid2: '', // 用户 ID
				userName2: '', // 手机号码
				byId: '',
				modal1: false,
				columns: [{
						title: '收益者UUID',
						align: 'center',
						key: 'uuid',
						render: (h, params) => {
							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
						}
					},
					{
						title: '收益者用户名',
						align: 'center',
						key: 'userName',
						render: (h, params) => {
							return h('div', params.row.userName == null ? '#' : params.row.userName)
						}
					},
					{
						title: '节点等级',
						align: 'center',
						key: 'nodeId',
						render: (h, params) => {
							return h('div', params.row.nodeId == null ? '#' : params.row.nodeId == 1 ? '普通节点' : params.row.nodeId == 2 ? '超级节点' : params.row.nodeId == 3 ? '社区节点' : params.row.nodeId == 4 ? '至尊节点' : '#')
						}
					},
					{
						title: '节点下总业绩',
						align: 'center',
						key: 'nodeAllNum',
						render: (h, params) => {
							return h('div', params.row.nodeAllNum == null ? '#' : this.Fixed(Number(params.row.nodeAllNum),4))
						}
					},
					{
						title: '节点奖励比例',
						align: 'center',
						key: 'ratio',
						render: (h, params) => {
							return h('div', params.row.ratio == null ? '#' : Number(params.row.ratio).mul(100) + '%')
						}
					},
					{
						title: '节点奖励',
						align: 'center',
						key: 'reward',
						render: (h, params) => {
							return h('div', params.row.reward == null ? '#' : this.Fixed(Number(params.row.reward),4))
						}
					},
					{
						title: '全网收益总量',
						align: 'center',
						key: 'netAllNum',
						render: (h, params) => {
							return h('div', params.row.netAllNum == null ? '#' : this.Fixed(Number(params.row.netAllNum),4))
						}
					},
					{
						title: '至尊节点人数',
						align: 'center',
						key: 'netMemberNum',
						render: (h, params) => {
							return h('div', params.row.netMemberNum == null ? '#' : this.Fixed(Number(params.row.netMemberNum),4))
						}
					},
					{
						title: '全网收益比例',
						align: 'center',
						key: 'netRatio',
						render: (h, params) => {
							return h('div', params.row.netRatio == null ? '#' : Number(params.row.netRatio).mul(100) + '%')
						}
					},
					{
						title: '全网奖励',
						align: 'center',
						key: 'netReward',
						render: (h, params) => {
							return h('div', params.row.netReward == null ? '#' : this.Fixed(Number(params.row.netReward),4))
						}
					},
					{
						title: '创建时间',
						align: 'center',
						key: 'createTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
					{
						title: '操作',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h(
								'div', {
									style: {
										cursor: 'pointer',
										color: '#2db7f5'
									},
									on: {
										click: () => {
											this.modal1 = true;
											this.byId = params.row.id;
											this.getQueryById();
										}
									}
								},
								'查看详情'
							)
						}
					}
				],
				columns1: [{
					title: '提供者UUID',
					align: 'center',
					key: 'uuid',
					render: (h, params) => {
						return h('div', params.row.uuid == null ? '#' : params.row.uuid)
					}
				}, {
					title: '提供者用户名',
					align: 'center',
					key: 'userName',
					render: (h, params) => {
						return h('div', params.row.userName == null ? '#' : params.row.userName)
					}
				}, {
					title: '今日总收益数量',
					align: 'center',
					key: 'num',
					render: (h, params) => {
						return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num, 4))
					}
				}, {
					title: '节点收益比例',
					align: 'center',
					key: 'ratio',
					render: (h, params) => {
						return h('div', params.row.ratio == null ? '#' : Number(params.row.ratio).mul(100) + '%')
					}
				}, {
					title: '节点奖励',
					align: 'center',
					key: 'rewardNum',
					render: (h, params) => {
						return h('div', params.row.rewardNum == null ? '#' : this.Fixed(params.row.rewardNum, 4))
					}
				}, {
					title: '创建时间',
					align: 'center',
					key: 'createTime',
					sortable: true,
					render: (h, params) => {
						return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
					}
				}],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询直推奖励
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/statistical/staticReward', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid,
					userName: this.userName,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/statistical/staticReward', this.qs.stringify({
							current: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							uuid: this.uuid,
							userName: this.userName,
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.jsonData.push({
										uuid: this.downList[index].uuid,
										userName: this.downList[index].userName,
										freezeNum: this.Fixed(this.downList[index].freezeNum, 4),
										idCrewardRatio: Number(this.downList[index].rewardRatio).mul(100) + '%',
										rewardNum: this.Fixed(this.downList[index].rewardNum, 4),
										availableNum: this.Fixed(this.downList[index].availableNum, 4),
										dedicatedNum: this.Fixed(this.downList[index].dedicatedNum, 4),
										createTime: this.stringToTime(this.downList[index].createTime),
									})
								})
								let str = `UUID,用户名,锁仓数量,释放比例,释放数量,可用(USDT),专用(USDT),赠送时间\n`;
								this.downLoad(this.jsonData, str, '静态收益');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getTime2(daterange) {
				this.dataValue2 = daterange
			},
			getQuery(page) {
				this.loading = true;
				isNaN(page) ? this.page = 1 : this.page = page;
				this.axios.get('/admin/statistical/node/reward', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						uuid: this.uuid,
						userName: this.userName,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			getQueryById(page) {
				this.loading2 = true;
				isNaN(page) ? this.page2 = 1 : this.page2 = page;
				this.axios.get('/admin/statistical/node/reward/info', {
					params: {
						current: this.page2, // 当前页【可选，默认1】
						size: this.pageSize2, // 每页记录数【可选，默认20】
						uuid: this.uuid2,
						rewardId: this.byId,
						userName: this.userName2,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list1 = res.data.data.records;
						this.info2 = res.data.data.total;
						this.loading2 = false;
					}
				})
			}
		}
	}
</script>